package com.better.common.mq;

import com.better.common.mongo.model.BaseModel;
import com.better.common.utils.GlobalUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by Administrator on 2017/9/21.
 */
@Component
public class HiSender {
    @Autowired
    private AmqpTemplate template;
    private Log logger = LogFactory.getLog(HiSender.class);
    public void send() {
        BaseModel b = new BaseModel();
        b.setId(GlobalUtil.createGlobalId());
        b.setCreate_by("张三");
        b.setCreate_time(new Date());
        template.convertAndSend("zxy",b);
    }


    public void sendDataToQueue(String queueKey, Object object) {
        try {
            template.convertAndSend(queueKey, object);
        } catch (Exception e) {
            logger.error(e);
        }

    }
}
